Skip to content

Fix functools.lru_cache() requiring an integer typed - #1359

Open
jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/lru-cache-typed-truthiness
Open

jseop-lim wants to merge 1 commit into
oracle:masterfrom
jseop-lim:fix/lru-cache-typed-truthiness

Conversation

@jseop-lim

Copy link
Copy Markdown
Contributor

Description

Part of #1291 (item 14).

_lru_cache_wrapper converts typed with ClinicConversion.Int, so a non-integer value raises TypeError. CPython parses it with the p format (_functoolsmodule.c#L1215) and takes its truth value.

AS-IS

>>> functools.lru_cache(maxsize=2, typed='x')
TypeError: 'str' object cannot be interpreted as an integer

TO-BE

>>> functools.lru_cache(maxsize=2, typed='x')
<function lru_cache.<locals>.decorating_function at 0x...>

(matching CPython)

Changes

  • Convert typed with ClinicConversion.Boolean.
  • Add a test to tests/test_functions.py.

Testing

mx python-jvm on darwin-aarch64, then mx graalpytest on test_functions.py (the new test fails on the unpatched build and passes with the fix) and the tagged test_functools (269 passed). mx python-checkcopyrights, mx eclipseformat and mx checkstyle are clean.

_lru_cache_wrapper converted typed to an int, so lru_cache(typed='x')
raised TypeError. CPython takes its truth value.

Signed-off-by: Jeongseop Lim <jeongseop_lim@korea.ac.kr>
@oracle-contributor-agreement oracle-contributor-agreement Bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant